package com.cloudcc.mobile.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.entity.chat.ChatMessage;

public class ChatAtAdapter extends BaseAdapter{
	private Context context;
	private List<ChatMessage> list;
	public ChatAtAdapter(Context context, List<ChatMessage> list) {
		super();
		this.context = context;
		this.list = list;
	}
	public void changeData(List<ChatMessage> list){
		this.list=list;
		notifyDataSetChanged();
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public ChatMessage getItem(int arg0) {
		return list.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView==null){
			convertView=LayoutInflater.from(context).inflate(R.layout.chat_guanyu_list,null);
			holder=new ViewHolder();
			holder.text=(TextView)convertView.findViewById(R.id.chat_text);
			holder.time=(TextView)convertView.findViewById(R.id.time);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		holder.text.setText(list.get(position).getContext());
		holder.time.setText(list.get(position).getTime());
		return convertView;
	}
	class ViewHolder{
		TextView text;
		TextView time;
	}
}
